<?php

if (!defined('BASEPATH'))
    exit('No direct script access allowed');


require_once('luckyflagcontroller.php');

class Project extends LuckyFlagController {

// View Names
    protected $viewAllProjects = 'viewallprojects';
    protected $projectDeleted = 'projectdeleted';
    protected $adminProjectView = 'adminprojectview';
    protected $userProjectView = 'userprojectview';
    protected $defaultProjectView = 'defaultprojectview';
    private $isAdmin;
    private $isUser;
    private $requiredData = array();

    /**
     * Overidden contruct method for the Project Controller.
     */
    public function __construct() {
        parent::__construct();
        $this->load->database();
        $this->load->helper('url');
        $this->load->model('projectmodel');
        $this->requiredData = array(
            'project_type' => array('0' => 'No Project Type'),
            'project_website' => array('0' => 'No Project Site'), 
            'project_email' => array('0' => 'No Project Contact Email'),           
        );
    }

    /**
     * Index page for the a Project. Loads a specific view for the Project 
     * depending on whether the User is 
     */
    public function index($project_id) {
        $isAdmin = $this->projectModel->isAdmin();
        $isUser = $this->projectModel->isUser();
        if ($this->$isAdmin) {
            $this->load->view($this->adminProjectView);
        } else if ($this->$isUser) {
            $this->load->view($this->userProjectView);
        } else {
            $this->load->view($this->defaultProjectView);
        }
    }

    /**
     * Method to insert a Project record into the project_table. This will create
     * a project record from scratch.
     *
     */
    public function insertProject() {
        $this->load->view('addProjectView', $this->data);
    }

    /**
     * Method to return all Projects within the system. This will only be used 
     * by administrators to get and overview of the current Projects. Returns 
     * the projects as an object into a nicely laid out jQuery DataTable.
     * 
     */
    public function viewAll() {
        $data['query'] = $this->projectmodel->getAllProjects();
        $this->load->view($this->viewAllProjects, $data);
    }

    /**
     * Deletes a Project dependant on the $id that is passed into it. This will 
     * find the Project Id within the Projects table and removed that record.
     *
     * @param int $project_id 
     */
    public function deleteProject($project_id) {
        $data['result'] = $this->projectModel->deleteProject();
        $this->load->view($this->projectDeleted, $data);
    }

    /**
     * This method will load in the Project menu into any Project related View 
     * that is is passed into. The menu is loaded from a static library, adding
     * a more flexible approach to editing the Menu offered without trawling 
     * through lots of code.
     * 
     * @return array $data[object] 
     * 
     */
    public function displayMenu() {
        $this->load->library('menus');
        $menu = new Menus();
        $data['menu'] = $menu->showProjectMenu();
    }

    /**
     * Updates a Project defined by the $id passed into the method. This will
     * update any fields passed in from the View and update the selected Project
     * with the respective columns updated in the Projects table.
     * 
     * @param int $project_id
     */
    public function updateProject($project_id) {
        
    }

    /**
     * Passes a Project record into the View dependant on the $id passed that's
     * passed as a parameter into it.
     * 
     * @param int $project_id 
     */
    public function view($project_id) {
        
    }

    /**
     * Creates a Note for the Project $id that is passed in as a parameter. 
     * Creates a relationship between a Note and Project in the Project Notes
     * intersection table.
     *
     * @param int $project_id
     */
    public function addProjectNote($project_id) {
        
    }

    /**
     * Edits the Note (this method is best placed in the respective parent's
     * class) that is associated to a Project. The $id of the Note is passed in
     * as a parameter and the fields within the Note are updated to the columns,
     * as well as the reference to the Project with the Project $id being passed
     * in also.
     * 
     * @param int $note_id
     * @param int $project_id
     */
    public function editProjectNote($note_id, $project_id) {
        
    }

    /**
     * Deletes an associated Note for a Project. This removes the the reference
     * for the Note in the Project Notes intersection table and then deletes the 
     * Note itself. Future implementations will allow for moving of Notes 
     * between Projects and Tasks. 
     * 
     * Method takes in the Note $id and the Project $id
     * 
     * @param int $note_id
     * @param int $project_id
     */
    public function deleteProjectNote($note_id, $project_id) {
        
    }

    /**
     * Returns a Project Note into the View. Takes in the Note $id and the $id
     * of the Project it is associated to.
     * 
     * @param int $note_id
     * @param int $project_id 
     */
    public function viewProjectNote($note_id, $project_id) {
        
    }

    /**
     * Returns all Notes associated to a Project from the passed in Project $id.
     * 
     * @param int $project_id
     */
    public function viewallNotes($project_id) {
        
    }

    /**
     * Adds a User to the Project, creates an association within the Project 
     * Users table with the passed in User and Project $id's
     * 
     */
    public function addUser() {
        
    }

    /**
     * Creates a Task and associates it to a Project, these are done with the 
     * passed in parameters Project and Task $id. Creates the relationship 
     * within the Project Tasks table.
     * 
     * @param int $task_id
     * @param int $project_id
     */
    public function addTask($task_id, $project_id) {
        
    }

    /**
     * Passes an object containing all the Project's Users into a View. Which 
     * Project is defined by the Project $id passed into the method parameter.
     * 
     * @param int $project_id
     */
    public function viewProjectUsers($project_id) {
        
    }

    /**
     * Passes an object containing all the Project's Tasks into a View. Which 
     * Project is defined by the Project $ud passed into the method parameter.
     * 
     * @param int $project_id
     */
    public function viewProjectTasks($project_id) {
        
    }

    /**
     * 
     * @todo Needs appropriate naming.
     */
    public function imguploadhandler() {
        
    }

    /**
     * 
     * @todo Needs appropriate naming convention
     */
    public function fileuploadhandler() {
        
    }

}
